<?php
define('NUM',7);
define('COLS',2);
$rows = ceil(NUM/COLS);

$count = 0;
$a = '';
?>
<table  border="1" width="80%" align="center">
<?php
for($i=1 ; $i<= $rows ;  $i++) {
?>
  <tr>
  <?php
  for($j=1 ; $j<= COLS ;  $j++) {
    $a .=" i=$i and j=$j<br>";
    // inc the counter
    if(++$count > NUM){
  ?>
      <td>&nbsp;</td>
  <?php
    } else {
  ?>
      <td><?php echo $count;?></td>

  <?php
    } // end else
  } // end inner for ?>
  </tr>
<?php
} // end outer for
?>
</table>

<?php
echo $a;
?>
